package org.apache.jsp.admin.procesa;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.io.*;
import java.util.*;
import beans.BeanEnlaces;
import mapping.Enlace;
import mapping.UrlEnlace;

public final class proc_005fbusquedaenlace_005fadmin_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();

  private static java.util.List _jspx_dependants;

  private javax.el.ExpressionFactory _el_expressionfactory;
  private org.apache.AnnotationProcessor _jsp_annotationprocessor;

  public Object getDependants() {
    return _jspx_dependants;
  }

  public void _jspInit() {
    _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
    _jsp_annotationprocessor = (org.apache.AnnotationProcessor) getServletConfig().getServletContext().getAttribute(org.apache.AnnotationProcessor.class.getName());
  }

  public void _jspDestroy() {
  }

  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;


    try {
      response.setContentType("text/html; charset=UTF-8");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			"../error/errorpage.jsp", true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write('\n');
      out.write('\n');
      out.write('\n');
      beans.BeanEnlaces mybean = null;
      synchronized (_jspx_page_context) {
        mybean = (beans.BeanEnlaces) _jspx_page_context.getAttribute("mybean", PageContext.PAGE_SCOPE);
        if (mybean == null){
          mybean = new beans.BeanEnlaces();
          _jspx_page_context.setAttribute("mybean", mybean, PageContext.PAGE_SCOPE);
        }
      }
      out.write("\n");
      out.write("<div id=\"resultBusqEnlaces\">\n");
      out.write("\t");
		
		
		//Numero de resultados de busqueda por pagina
		int resultadosporpagina = 10;
		final int MAX_LENGTH = 60;
		//Vemos por cual tupla hemos de comenzar la busqueda
		System.out.println(request.getParameter("iniciotupla"));
		int inicTupla = Integer.parseInt(request.getParameter("iniciotupla"));
		mybean.conectar();
		String [] tipoEnlacesElegidos = request.getParameterValues("tipo_enlace");
		String nombreEnlace = request.getParameter("nom_enlace");
		String urlenlace = request.getParameter("url_enlace");
		List listEnlaces = mybean.getEnlaces(nombreEnlace, tipoEnlacesElegidos, urlenlace, resultadosporpagina, inicTupla);
		if(listEnlaces == null)
	    	out.println("<p>ERROR</p>");
		else if (!listEnlaces.isEmpty()) { 
      out.write("\n");
      out.write("\t\t<form id=\"formlistado\" action=\"proc_busquedaenlace_admin.jsp\" method=\"get\" onsubmit=\"return false;\">\n");
      out.write("\t\t\n");
      out.write("\t\t<table border=\"1\" width=\"91%\" valign=\"top\" cellspacing = \"0\" cellpadding=\"0\">\n");
      out.write("\t\t\t<tbody id=\"cuerpoTablaEnlaces\">\n");
      out.write("\t        <tr class=\"trcabeclista\">\n");
      out.write("\t        \t<td class=\"tdchk\"><b>&nbsp;</b></td>\n");
      out.write("\t            <td id=\"tdnomenlace\"><b>NOMBRE</b></td>\n");
      out.write("\t            <td id=\"tdurlenlace\"><b>URL</b></td>\n");
      out.write("\t            <td id=\"tdtipoenlace\"><b>TIPO</b></td>\n");
      out.write("\t            <td class=\"tdbts\">&nbsp;</td>\n");
      out.write("\t        </tr>\n");
      out.write("\t\t\t");

			Iterator it2 = listEnlaces.iterator();
			while(it2.hasNext()) {
				Enlace enl = new Enlace();
				enl = (Enlace) it2.next();
				int id_enlace = enl.getId_enlace();
			
      out.write("\n");
      out.write("\t\t\t<tr class=\"listado\" id = \"fila");
      out.print(id_enlace);
      out.write("\" valign=\"top\" \n");
      out.write("\t\t\tonmouseover=\"iluminaFila(this)\" onmouseout=\"oscureceFila(this)\">\n");
      out.write("\t\t\t\t<td class=\"tdcenter\">\n");
      out.write("       \t\t\t\t<input type=\"checkbox\" class=\"chkboxes\" name=\"chkbx_enlaces\" id=\"");
      out.print(id_enlace);
      out.write("\"\n");
      out.write("       \t\t\t\tvalue=\"");
      out.print(id_enlace);
      out.write("\" onclick=\"habilitarBotones(this, 1); habilitarBorrarTodo();\"/>\n");
      out.write("       \t\t\t</td>\n");
      out.write("\t\t\t\t<td id=\"tdnomenlace\">");
      out.print(enl.getEnlace());
      out.write("</td>\n");
      out.write("\t\t\t\t<td>\t\t\t\t\n");
      out.write("\t\t       \t");

		       	List listaUrls = enl.getListaUrls();
		        if(listaUrls != null){
		        	Iterator it = listaUrls.iterator();
		        	while(it.hasNext()) {
		        		UrlEnlace url = new UrlEnlace();
		            	url = (UrlEnlace) it.next();
		            	String str_url = url.getUrl_enlace();
		                if(str_url.trim().length() >= MAX_LENGTH) {
		                   str_url = str_url.substring(0, MAX_LENGTH + 1) + "...";
		                }	
		            	String desc_url = url.getDescripcion_url();
		            	if(desc_url == null) 
		            		desc_url = "&nbsp;";
		         
      out.write("\t\t                   \n");
      out.write("\t\t            <div class=\"tdurl\"><a href=\"");
      out.print(str_url);
      out.write("\" target=\"_blank\" title=\"");
      out.print(desc_url);
      out.write('"');
      out.write('>');
      out.print(str_url);
      out.write("</a></div>\n");
      out.write("\t\t         \n");
      out.write("\t           \t\t");
} // fin while
	      		} // fin if
	       		
      out.write("  \n");
      out.write("\t       \t\t</td>                    \t      \t\t\n");
      out.write("\t       \t\t<td align=\"center\">");
      out.print( enl.getTipo_enlace());
      out.write("</td>\n");
      out.write("\t       \t\t<td id=\"tdbtneditborrar\" class=\"tdcenter\">\n");
      out.write("\t       \t\t\t<button class=\"btnimg\" id=\"btedit");
      out.print(id_enlace);
      out.write("\" onclick=\"direccionar('modificaenlace.jsp?id_enlace=");
      out.print(id_enlace);
      out.write("')\" disabled=\"disabled\">\n");
      out.write("\t       \t\t\t\t<img id=\"imgbtedit");
      out.print(id_enlace);
      out.write("\" src=\"../images/web/editdis.png\" alt=\"Editar\"/>\n");
      out.write("\t       \t\t\t</button>\n");
      out.write("\t       \t\t\t<button class=\"btnimg\" id=\"btborr");
      out.print(id_enlace);
      out.write("\" onclick=\"borrar()\" disabled=\"disabled\">\n");
      out.write("\t       \t\t\t\t<img id=\"imgbtborr");
      out.print(id_enlace);
      out.write("\" src=\"../images/web/borradis.png\" alt=\"Borrar\"/>\n");
      out.write("\t       \t\t\t</button>\n");
      out.write("\t       \t\t</td>\n");
      out.write("\t\t\t");
}//fin while	     
	     
      out.write("\n");
      out.write("\t</tbody>\n");
      out.write("</table>\n");
      out.write("\n");
      out.write("\t<br/>\n");
      out.write("\t\t<button class=\"mybtn\" id=\"btselect\" onclick=\"selectAll('chkboxes', 1)\" onmouseover=\"goLite(this)\" onmouseout=\"goDim(this)\">Seleccionar todo</button>\n");
      out.write("    \t<button class=\"mybtn\" id=\"btunselect\" onclick=\"deselectAll('chkboxes', 1)\" onmouseover=\"goLite(this)\" onmouseout=\"goDim(this)\">Deseleccionar todo</button>\n");
      out.write("    \t<button class=\"mybtn\" id=\"btborrartodo\" disabled=\"disabled\" onclick=\"borrar()\" onmouseover=\"goLite(this)\" onmouseout=\"goDim(this)\">Borrar seleccionados</button>\n");
      out.write("    </form>\t\n");
      out.write("    ");
 }//fin else	 
   	 else { 
      out.write("\n");
      out.write("    \t<center><p>No se han encontrado resultados para la b&uacute;squeda</p></center>\n");
      out.write("   ");
 }	
      out.write("\n");
      out.write("   \t\n");
      out.write("</div>\n");
      out.write(" <div align=\"center\">\n");
      out.write("   \t");

	if(inicTupla > 1){
	
      out.write("\n");
      out.write("    \t<button class=\"mybtn\" id=\"ant\" onmouseover=\"goLite(this)\" onmouseout=\"goDim(this)\"\n");
      out.write("    \tonclick=\"retrocedeCursorResultSet('lista_enlaces','form_enlaces','proc_busquedaenlace_admin.jsp','get',");
      out.print(resultadosporpagina);
      out.write(")\">Anterior</button>\n");
      out.write("    ");

	}
	if(inicTupla+resultadosporpagina < mybean.contadorTuplas){
	
      out.write("\n");
      out.write("    \t<button class=\"mybtn\" id=\"sig\" onmouseover=\"goLite(this)\" onmouseout=\"goDim(this)\"\n");
      out.write("    \tonclick=\"adelantaCursorResultSet('lista_enlaces','form_enlaces','proc_busquedaenlace_admin.jsp','get',");
      out.print(resultadosporpagina);
      out.write(")\">Siguiente</button>\n");
      out.write("    ");

	}
	mybean.desconectar();
 
      out.write("\n");
      out.write("</div>\t\n");
      out.write("<div id=\"res_borrado\"></div>\n");
      out.write("<div id=\"modenlace\"></div>\n");
      out.write("\n");
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try { out.clearBuffer(); } catch (java.io.IOException e) {}
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}
